export const util = {
	guid() {
		function S4() {
			return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
		}
		return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
	},

	getFileSuffix(filename) {
		var index = filename.lastIndexOf(".");
		return filename.substr(index + 1);
	},
	timestampToTime(timestamp, format) {
		if (!format) format = "yyyy-MM-dd hh:mm:ss";
		var date = new Date(timestamp);
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate();
		var hour = date.getHours();
		var minute = date.getMinutes();
		var second = date.getSeconds();

		format = format.replace("yyyy", year)
			.replace("MM", (String(month).length > 1 ? month : '0' + month))
			.replace("dd", (String(day).length > 1 ? day : '0' + day))
			.replace("hh", (String(hour).length > 1 ? hour : '0' + hour))
			.replace("mm", (String(minute).length > 1 ? minute : '0' + minute))
			.replace("ss", (String(second).length > 1 ? second : '0' + second));
		return format;
	},
	toast(title) {
		if (title) {
			uni.showToast({
				icon: 'none',
				title: title
			})
		}
	},
	formatFileSize(value) {
		if (null == value || value == '') {
			return "0 Bytes";
		}
		var unitArr = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
		var index = 0,
			srcsize = parseFloat(value);
		index = Math.floor(Math.log(srcsize) / Math.log(1024));
		var size = srcsize / Math.pow(1024, index);
		size = size.toFixed(2);
		return size + unitArr[index];
	}
}
